/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class BeijingSearchEngine extends SearchEngine
/*     */ {
/*  19 */   private static Logger logger = Logger.getLogger(BeijingSearchEngine.class
/*  20 */     .getName());
/*     */ 
/*  22 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*  29 */     BeijingSearchEngine searchEngine = new BeijingSearchEngine(
/*  30 */       "北京融汇信达投资有限公司");
/*  31 */     Map items = searchEngine.getCompanyByWeb();
/*  32 */     System.out.println(items);
/*     */   }
/*     */ 
/*     */   public BeijingSearchEngine(String name)
/*     */   {
/*  37 */     this.name = standardizedName(name);
/*     */ 
/*  39 */     this.params.put("名称：", "CompanyName");
/*  40 */     this.params.put("注册号：", "SN");
/*  41 */     this.params.put("住所：", "Address");
/*  42 */     this.params.put("法定代表人：", "Header");
/*  43 */     this.params.put("注册资本：", "RegisteredCapital");
/*  44 */     this.params.put("公司类型：", "CompanyType");
/*  45 */     this.params.put("许可经营项目：", "BusinessScope2");
/*  46 */     this.params.put("一般经营项目：", "BusinessScope");
/*  47 */     this.params.put("营业期限自：", "OperatingPeriodStart");
/*  48 */     this.params.put("营业期限至：", "OperatingPeriodEnd");
/*  49 */     this.params.put("成立日期：", "FoundedDate");
/*  50 */     this.params.put("登记机关：", "RegistrationAuthority");
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */   {
/*  56 */     if (!isValid(this.name)) {
/*  57 */       return null;
/*     */     }
/*  59 */     String url = null;
/*     */     try
/*     */     {
/*  62 */       url = "http://qyxy.baic.gov.cn/lucene/luceneAction!NetCreditLucene.dhtml?idFlag=qyxy&queryStr=" + URLEncoder.encode(this.name.trim(), "utf-8");
/*     */     } catch (UnsupportedEncodingException e) {
/*  64 */       url = "http://qyxy.baic.gov.cn/lucene/luceneAction!NetCreditLucene.dhtml?idFlag=qyxy&queryStr=" + this.name.trim();
/*     */     }
/*     */     try {
/*  67 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  68 */         .timeout(10000).get();
/*  69 */       Elements links = doc.select("td[class=cx00] font a");
/*  70 */       String detailUrl = null;
/*  71 */       if ((links != null) && (links.size() >= 1)) {
/*  72 */         detailUrl = links.get(0).attr("onclick");
/*     */       }
/*     */ 
/*  75 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0)) {
/*  76 */         return null;
/*     */       }
/*  78 */       int s = detailUrl.indexOf("'");
/*  79 */       int e = detailUrl.indexOf("'", s + 1);
/*  80 */       if ((s <= 0) || (e <= 0) || (s >= e)) {
/*  81 */         return null;
/*     */       }
/*     */ 
/*  84 */       detailUrl = "http://qyxy.baic.gov.cn" + 
/*  85 */         detailUrl.substring(s + 1, e);
/*     */ 
/*  88 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  89 */         .get();
/*  90 */       links = doc.select("table[class=f-lbiao] td");
/*  91 */       if (links == null) {
/*  92 */         return null;
/*     */       }
/*     */ 
/*  95 */       Map info = new HashMap();
/*     */ 
/*  97 */       for (Element item : links) {
/*  98 */         String key = item.text().trim();
/*  99 */         if (this.params.containsKey(key))
/*     */         {
/* 102 */           info.put((String)this.params.get(key), item.nextElementSibling().html());
/*     */         }
/*     */       }
/* 105 */       info.put("OperatingPeriod", info.get("OperatingPeriodStart") + " - " + 
/* 106 */         info.get("OperatingPeriodEnd"));
/* 107 */       if ((info.get("BusinessScope2") != null) && 
/* 108 */         (info.get("BusinessScope2").toString().trim().length() > 0)) {
/* 109 */         info.put("BusinessScope", info.get("BusinessScope") + " 许可经营项目： " + 
/* 110 */           info.get("BusinessScope2"));
/*     */       }
/* 112 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 113 */       if (info.size() > 1)
/*     */       {
/* 115 */         saveDB(info);
/*     */       }
/*     */ 
/* 118 */       return info;
/*     */     } catch (IOException e) {
/* 120 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 123 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.BeijingSearchEngine
 * JD-Core Version:    0.6.1
 */